package com.ds.api.utils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

/**
 * 
 * @className: DateUtil
 * @description: 日期处理集合类 主要功能：日期格式转换,日期比较。
 * @author yangzhiwei
 */
public class DateUtil {

    /**
     * 
     * @description: 格式化日期以字符串形式返回
     * @param date 日期
     * @param format 格式
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String format(Date date, String format) {
        if (date == null) {
            return "";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }

    /**
     * 
     * @description: 格式化日期 返回 如(2000-01-10 12:00:20)
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toSeconds(Date date) {
        return format(date, "yyyy-MM-dd HH:mm:ss");
    }
    
    public static String toSeconds1(Date date) {
        return format(date, "yyyy年MM月dd日HH时mm分");
    }
    /**
     * 
     * @description: 转化为毫秒
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toMillisecond(Date date) {
        return format(date, "yyyyMMddHHmmssSSS");
    }

    /**
     * 
     * @description: 转化日期
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toMinute(Date date) {
        return format(date, "yyyy-MM-dd HH:mm");
    }

    /**
     * 
     * @description: 格式化日期 返回 如(05/18)
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toMonthAndDay(Date date) {
        return format(date, "MM/dd");
    }

    /**
     * 
     * @description: 转换日期为-月-日
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toMDay(Date date) {
        return format(date, "MM-dd");
    }

    /**
     * 
     * @description: 格式化日期 返回 如(05/18 16:10)
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toDaySeconds(Date date) {
        return format(date, "MM/dd HH:mm");
    }

    /**
     * 
     * @description: 格式化日期 返回 如(2000-01-10)
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toDay(Date date) {
        return format(date, "yyyy-MM-dd");
    }

    /**
     * 
     * @description: 格式化日期 返回 如(2000.01)
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toYearMonth(Date date) {
        return format(date, "yyyy.MM");
    }

    /**
     * 
     * @description: 格式化日期 返回 如(MM月dd日 HH:mm)
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toMonthDate(Date date) {
        return format(date, "MM月dd日 HH:mm");
    }

    /**
     * 
     * @description: 截取日期 (5月5日)
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toMonthDateNoHour(Date date) {
        String dateStr = format(date, "MM月dd日");
        if (dateStr.startsWith("0")) {
            dateStr = dateStr.substring(1);
        }
        return dateStr;
    }

    /**
     * 
     * @description: 格式化日期 返回 如(20000110)
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toShortDay(Date date) {
        return format(date, "yyyyMMdd");
    }

    /**
     * 
     * @description: 格式化日期 返回月份
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toMonth(Date date) {
        return format(date, "MM");
    }

    /**
     * 
     * @description: 格式化日期 返回日期
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toShortdd(Date date) {
        return format(date, "dd");
    }

    /**
     * 
     * @description: 格式化日期 返回时分秒
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toShortSeconds(Date date) {
        return format(date, "HH:mm:ss");
    }

    /**
     * 
     * @description: 格式化日期 返回年份
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String toShortYear(Date date) {
        return format(date, "yyyy");
    }

    /**
     * 
     * @description: 以指定的格式返回日期
     * @param s 日期
     * @param format 格式
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date valueof(String s, String format) {
        return parse(s, format);
    }

    /**
     * 
     * @description: 以默认的格式返回日期
     * @param s
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date valueOfStandard(String s) {
        return parse(s, "yyyy-MM-dd");
    }

    /**
     * 
     * @description: 返回日期 返回 如(20000110)
     * @param s
     * @return
     * @throws ParseException
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date valueOfShort(String s) throws ParseException {
        return parse(s, "yyyyMMdd");
    }

    /**
     * 
     * @description: 判断日期是否相同
     * @param d1 日期
     * @param d2 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static boolean isSameDay(Date d1, Date d2) {
        return DateUtil.roundToDay(d1).getTime() == DateUtil.roundToDay(d2).getTime();
    }

    /**
     * 
     * @description: 比较日期大小返回布尔型
     * @param d1 日期
     * @param d2 日期
     * @return d1 > d2 true
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static boolean compareDay(Date d1, Date d2) {
        return d1.compareTo(d2) < 0 ? false : true;
    }

    /**
     * 
     * @description: 以指定格式格式化日期
     * @param s 日期
     * @param format 格式
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    private static Date parse(String s, String format) {
        if (s == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
            return sdf.parse(s);
        }
        catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 
     * @description: 以默认格式格式化日期 yyyy-MM-dd HH:mm:ss
     * @param s 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date parse(String s) {
        if (s == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(s);
        }
        catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 
     * @description: 日期相减 返回天数
     * @param big 大的日期
     * @param small 小的日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static double dayInterval(Date big, Date small) {
        big = roundToDay(big);
        small = roundToDay(small);
        return (big.getTime() - small.getTime()) / (1000 * 60 * 60 * 24);
    }

    /**
     * 
     * @description: 日期相减 返回天数
     * @param big 大的日期
     * @param small 小的日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static int dayCount(Date big, Date small) {
        big = roundToDay(big);
        small = roundToDay(small);
        return new Double((big.getTime() - small.getTime()) / (1000 * 60 * 60 * 24)).intValue();
    }

    /**
     * 
     * @description: 日期相减 返回分钟
     * @param big 大的日期
     * @param small 小的日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static double minuteInterval(Date big, Date small) {
        return (big.getTime() - small.getTime()) / (1000 * 60);
    }

    /**
     * 
     * @description: 日期相减 返回小时
     * @param big 大的日期
     * @param small 小的日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static double newMinuteInterval(Date big, Date small) {
        return (big.getTime() - small.getTime()) / (1000 * 60 * 60);
    }

    /**
     * 
     * @description: 日期相减 返回秒数
     * @param big 大的日期
     * @param small 小的日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static double secondInterval(Date big, Date small) {
        return (big.getTime() - small.getTime()) / 1000;
    }

    /**
     * 
     * @description: 日期相减 以几个星期的形式返回
     * @param small 小的日期
     * @param big 大的日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static int workDayInterval(Date small, Date big) {
        big = roundToDay(big);
        small = roundToDay(small);

        GregorianCalendar smallGc = new GregorianCalendar();
        smallGc.setTime(small);

        GregorianCalendar bigGc = new GregorianCalendar();
        bigGc.setTime(big);

        int workDays = 0;
        long bigTime = bigGc.getTime().getTime();
        while (smallGc.getTime().getTime() < bigTime) {
            int week = smallGc.get(Calendar.DAY_OF_WEEK);
            // int month = smallGc.get(Calendar.MONTH) + 1;
            smallGc.add(Calendar.DATE, 1);
            if (week == Calendar.SATURDAY || week == Calendar.SUNDAY) {
                continue;
            }
            else {
                workDays++;
            }
        }
        return workDays;
    }

    /**
     * 
     * @description: 判断日期是否为周六和周日
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static boolean isWorkDay(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        int week = gc.get(Calendar.DAY_OF_WEEK);
        if (week == Calendar.SATURDAY || week == Calendar.SUNDAY) {
            return true;
        }
        return false;
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date roundToDay(Date date) {
        date = roundToHour(date);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.HOUR_OF_DAY, 0);
        return gc.getTime();
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date roundToHour(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.MINUTE, 0);
        gc.set(Calendar.SECOND, 0);
        gc.set(Calendar.MILLISECOND, 0);
        return gc.getTime();
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @param num
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date addYear(Date date, int num) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.YEAR, num);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date roundToMinute(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.SECOND, 0);
        gc.set(Calendar.MILLISECOND, 0);
        return gc.getTime();
    }

    /**
     * 
     * @description: 返回日期的下一天
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date nextDate(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, 1);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: 返回日期的下三天
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date nextThreeDate(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, 3);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: 返回日期的下一个小时
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date nextHour(Date date) {
        date = add(date, Calendar.HOUR, 1);
        return roundToHour(date);
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @param field
     * @param amount
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date add(Date date, int field, int amount) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(field, amount);
        return gc.getTime();
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @param amount
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date addDay(Date date, int amount) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, amount);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: 返回日期的上一天
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date lastDate(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, -1);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: 返回日期的上一天当前小时
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date newlastDate(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, -1);
        return roundToHour(gc.getTime());
    }

    /**
     * 
     * @description: 返回当前日期的前或后i天
     * @param date 当前日期
     * @param i 前或后的天数前为负
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date lastDate(Date date, int i) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, i);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: 返回当前日期的前或后i天当前小时
     * @param date 当前日期
     * @param i 前或后的天数前为负
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date lastDateToH(Date date, int i) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, i);
        return roundToHour(gc.getTime());
    }

    /**
     * 
     * @description: 返回当前日期的前或后i天的当前时间
     * @param date
     * @param i
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date lastDateToM(Date date, int i) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, i);
        return roundToMinute(gc.getTime());
    }

    /**
     * 
     * @description: 返回日期的上一个月
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date lastMonth(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.MONTH, -1);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: 返回日期的上三天
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date lastThreeDate(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, -3);
        return gc.getTime();
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date roundToMonth(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.DATE, 1);
        gc.set(Calendar.HOUR_OF_DAY, 0);
        gc.set(Calendar.MINUTE, 0);
        gc.set(Calendar.SECOND, 0);
        gc.set(Calendar.MILLISECOND, 0);
        return gc.getTime();
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date roundToTenMinute(Date date) {
        Date minuteTime = DateUtil.roundToMinute(date);
        int minuteNum = DateUtil.getTimeField(minuteTime, Calendar.MINUTE);
        minuteNum = minuteNum / 10 * 10;
        minuteTime = DateUtil.setTimeField(minuteTime, Calendar.MINUTE, minuteNum);
        return minuteTime;
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date getFirstDayOfYear(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.DATE, 1);
        gc.set(Calendar.MONTH, 0);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date getLastDayOfYear(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.DATE, 31);
        gc.set(Calendar.MONTH, 11);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: 获取指定日期的第一天
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date getFirstDayOfMonth(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.DATE, 1);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: 获取指定日期在周的第一天
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date getFirstDayOfWeek(Date date) {
        while (DateUtil.getTimeField(date, Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
            date = DateUtil.lastDate(date);
        }
        return date;
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date getLastDayOfMonth(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);

        gc.add(Calendar.MONTH, 1);
        gc.set(Calendar.DATE, 0);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date getLastDayOfWeek(Date date) {
        while (DateUtil.getTimeField(date, Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
            date = DateUtil.nextDate(date);
        }
        return date;
    }

    /**
     * 
     * @description: 返回oracle的日期函数格式
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String oracleToDate(Date date) {
        return "to_date('" + DateUtil.format(date, "yyyy-MM-dd") + "', 'yyyy-mm-dd')";
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @param field
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static int getTimeField(Date date, int field) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        return gc.get(field);
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @param field
     * @param timeNum
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date setTimeField(Date date, int field, int timeNum) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(field, timeNum);
        return gc.getTime();
    }

    /**
     * 
     * @description: 判断日期是 pm还是 am
     * @param date 日期
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String ampm(Date date) {
        int hours = getTimeField(date, Calendar.HOUR_OF_DAY);

        if (hours <= 12) {
            return "A";
        }
        return "P";
    }

    /**
     * 
     * @description: TODO
     * @param startTime
     * @param endTime
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String ampm(Date startTime, Date endTime) {
        String start = ampm(startTime);
        String end = ampm(endTime);

        if ("A".equals(start) && "A".equals(end)) {
            return "A";
        }
        else if ("P".equals(start) && "P".equals(end)) {
            return "P";
        }
        return "N";

    }

    /**
     * 
     * @description: TODO
     * @param date
     * @param ampm
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date[] getTimeInterval(Date date, String ampm) {

        Date startDate = (Date) date.clone();
        Date endDate = (Date) date.clone();

        if ("A".equals(ampm)) {
            // startDate.setHours(9);
            startDate = setTimeField(startDate, Calendar.HOUR_OF_DAY, 9);
            endDate = setTimeField(endDate, Calendar.HOUR_OF_DAY, 12);
        }
        else if ("P".equals(ampm)) {
            startDate = setTimeField(startDate, Calendar.HOUR_OF_DAY, 12);
            endDate = setTimeField(endDate, Calendar.HOUR_OF_DAY, 18);
        }
        else if ("N".equals(ampm)) {
            startDate = setTimeField(startDate, Calendar.HOUR_OF_DAY, 9);
            endDate = setTimeField(endDate, Calendar.HOUR_OF_DAY, 18);
        }

        startDate = setTimeField(startDate, Calendar.MINUTE, 0);
        endDate = setTimeField(endDate, Calendar.MINUTE, 0);
        startDate = setTimeField(startDate, Calendar.SECOND, 0);
        endDate = setTimeField(endDate, Calendar.SECOND, 0);

        Date[] dates = new Date[2];
        dates[0] = startDate;
        dates[1] = endDate;

        return dates;
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String getChineseWeekName(Date date) {

        int w = DateUtil.getTimeField(date, Calendar.DAY_OF_WEEK);
        String cw = "";
        switch (w) {
        case Calendar.SUNDAY:
            cw = "星期日";
            break;
        case Calendar.MONDAY:
            cw = "星期一";
            break;
        case Calendar.TUESDAY:
            cw = "星期二";
            break;
        case Calendar.WEDNESDAY:
            cw = "星期三";
            break;
        case Calendar.THURSDAY:
            cw = "星期四";
            break;
        case Calendar.FRIDAY:
            cw = "星期五";
            break;
        case Calendar.SATURDAY:
            cw = "星期六";
            break;
        default:
            break;
        }
        return cw;
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String getChineseMonthName(Date date) {
        int w = DateUtil.getTimeField(date, Calendar.MONTH);
        String cw = "";
        switch (w) {
        case Calendar.JANUARY:
            cw = "一月";
            break;
        case Calendar.FEBRUARY:
            cw = "二月";
            break;
        case Calendar.MARCH:
            cw = "三月";
            break;
        case Calendar.APRIL:
            cw = "四月";
            break;
        case Calendar.MAY:
            cw = "五月";
            break;
        case Calendar.JUNE:
            cw = "六月";
            break;
        case Calendar.JULY:
            cw = "七月";
            break;
        case Calendar.AUGUST:
            cw = "八月";
            break;
        case Calendar.SEPTEMBER:
            cw = "九月";
            break;
        case Calendar.OCTOBER:
            cw = "十月";
            break;
        case Calendar.NOVEMBER:
            cw = "十一月";
            break;
        case Calendar.DECEMBER:
            cw = "十二月";
            break;
        default:
            break;
        }
        return cw;
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date nextSevenDate(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, 7);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date previousSevenDate(Date date) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.DATE, -7);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @param num
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date previousYear(Date date, int num) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(Calendar.YEAR, -num);
        return roundToDay(gc.getTime());
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @param hour
     * @param minute
     * @param second
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date setTimeOfDay(Date date, int hour, int minute, int second) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.HOUR_OF_DAY, hour);
        gc.set(Calendar.MINUTE, minute);
        gc.set(Calendar.SECOND, second);
        gc.set(Calendar.MILLISECOND, 0);
        return gc.getTime();
    }

    /**
     * 
     * @description: TODO
     * @param oldStartTime
     * @param oldEndTime
     * @param newStartTime
     * @param newEndTime
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static boolean isTimeContain(Date oldStartTime, Date oldEndTime, Date newStartTime, Date newEndTime) {
        if (!(oldEndTime.getTime() <= newStartTime.getTime() || oldStartTime.getTime() >= newEndTime.getTime())) {
            return true;
        }

        return false;
    }

    /**
     * 取日期的最小值
     * 
     * @param d1 日期
     * @param d2 日期
     * @return
     */
    public static Date min(Date d1, Date d2) {
        if (d1.getTime() > d2.getTime()) {
            return d2;
        }
        else {
            return d1;
        }
    }

    /**
     * 求日期的最大值
     * 
     * @param d1 日期
     * @param d2 日期
     * @return
     */
    public static Date max(Date d1, Date d2) {
        if (d1.getTime() < d2.getTime()) {
            return d2;
        }
        else {
            return d1;
        }
    }

    /**
     * 比较时间 如date1小于date2返回1 date1大于date2返回-1否则返回0
     * 
     * @param date1 日期
     * @param date2 日期
     * @return
     */
    public static int compareTime(Date date1, Date date2) {
        GregorianCalendar g1 = new GregorianCalendar();
        g1.setTime(date1);
        GregorianCalendar g2 = new GregorianCalendar();
        g1.setTime(date2);

        clearYMD(g1);
        clearYMD(g2);

        if (g1.before(g2)) {
            return 1;
        }
        else if (g2.before(g1)) {
            return -1;
        }

        return 0;
    }

    /**
     * 
     * @description: 清空年月日
     * @param g 日期对象
     * @author yangzhiwei
     * @date 2017-5-15
     */
    private static void clearYMD(GregorianCalendar g) {
        g.set(Calendar.YEAR, 1900);
        g.set(Calendar.MONTH, 0);
        g.set(Calendar.DATE, 1);
    }

    /**
     * 
     * @description: 显示开始月份和结束月份之间的所有月份
     * @param startMonth 开始月份
     * @param endMonth 结束月份
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static List<Date> listMonthOption(Date startMonth, Date endMonth) {
        List<Date> list = new ArrayList<Date>();

        Date date = endMonth;
        while (date.getTime() - startMonth.getTime() > 0) {
            list.add(date);
            date = DateUtil.add(date, Calendar.MONTH, -1);
        }
        return list;
    }

    /**
     * 
     * @description: 重载方法
     * @param monthNum 月份差
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static List<Date> listMonthOption(int monthNum) {
        Date endDate = new Date();
        Date startDate = DateUtil.add(endDate, Calendar.MONTH, -monthNum);

        return listMonthOption(startDate, endDate);
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static List<Date> getWeekList(Date date) {
        Date day = getFirstDayOfWeek(date);
        List<Date> dates = new ArrayList<Date>();
        for (int i = 0; i < 7; i++) {
            Date temp = lastDate(day, i);
            dates.add(temp);
            if (isSameDay(temp, new Date())) {
                break;
            }
        }
        return dates;
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static boolean isNotEmptyPreviousWeek(Date date) {
        return getFirstDayOfWeek(date).compareTo(new Date()) < 0 ? true : false;
    }

    /**
     * 
     * @description: TODO
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static long getCurrentYear() {
        GregorianCalendar g1 = new GregorianCalendar();
        g1.setTime(new Date());
        long year = g1.get(GregorianCalendar.YEAR);

        return year;
    }

    /**
     * 
     * @description: TODO
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static long getCurrentMonth() {
        GregorianCalendar g1 = new GregorianCalendar();
        g1.setTime(new Date());
        long month = g1.get(GregorianCalendar.MONTH);
        month++;
        return month;
    }

    /**
     * 
     * @description: TODO
     * @param year
     * @param month
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date getBudgetStartDate(int year, int month) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(new Date());
        gc.set(GregorianCalendar.DATE, 1);
        gc.set(GregorianCalendar.MONTH, 0);
        gc.set(GregorianCalendar.YEAR, new Long(year).intValue());
        Date dateStart = DateUtil.roundToDay(gc.getTime());

        return dateStart;
    }

    /**
     * 
     * @description: TODO
     * @param year
     * @param month
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date getBudgetEndDate(int year, int month) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(new Date());
        gc.set(GregorianCalendar.DATE, 1);
        gc.set(GregorianCalendar.MONTH, month - 1);
        gc.set(GregorianCalendar.YEAR, new Long(year).intValue());
        Date date = DateUtil.roundToDay(gc.getTime());

        return getLastDayOfMonth(date);
    }

    /**
     * 
     * @description: TODO
     * @param year
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static Date getYear(int year) {
        GregorianCalendar gc = new GregorianCalendar();

        gc.set(GregorianCalendar.YEAR, new Long(year).intValue());
        Date date = DateUtil.roundToDay(gc.getTime());

        return date;
    }

    /**
     * 
     * @description: TODO
     * @param date
     * @param pattern
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String dateToString(Date date, String pattern) {

        if (date == null) {

            return null;
        }

        try {

            SimpleDateFormat sfDate = new SimpleDateFormat(pattern);
            sfDate.setLenient(false);

            return sfDate.format(date);
        }
        catch (Exception e) {

            return null;
        }
    }

    /**
     * 
     * @description: 将毫秒转化为“时：分：秒” 的形式
     * @param millisecond
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String millisecondToFormat(long millisecond) {

        long hour = millisecond / (1000 * 3600);
        long minit = millisecond % (1000 * 3600) / (1000 * 60);
        long second = millisecond % (1000 * 60) / 1000;

        return String.format("%02d", hour) + ":" + String.format("%02d", minit) + ":" + String.format("%02d", second);
    }

    /**
     * 
     * @description: TODO
     * @param millisecond
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String millisecondToFormat1(long millisecond) {

        long hour = millisecond / (1000 * 3600);
        long minit = millisecond % (1000 * 3600) / (1000 * 60);

        return String.format("%02d", hour) + "小时" + String.format("%02d", minit) + "分钟";
    }

    /**
     * 
     * @description: 两日期相减 得到时分
     * @param big
     * @param small
     * @return
     * @author yangzhiwei
     * @date 2017-5-15
     */
    public static String getHourMinte(Date big, Date small) {
        Long millisecond = big.getTime() - small.getTime();
        return millisecondToFormat1(millisecond);
    }

    /**
     * 
     * @description: 获取当前系统时间
     * @return
     * @author yangzhiwei
     * @date 2017-5-17
     */
    public static Timestamp getCurrTimestamp() {
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        return timestamp;
    }
}
